<template>
	<div>
		<view class="main">
			<image src="../../static/images/dly.png" style="width: 100%;height: 100%;" mode="aspectFill"></image>
		</view>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				code: '',
				isLogin:false
			}
		},
		onLoad(e) {
			console.log(e,'登录页',getApp().globalData);
			// if(true){
			// 	uni.reLaunch({
			// 		url: '../index/index'
			// 	})
			// }//要做判断，如果登录过就直接跳转首页
			uni.$on('login', function(data) {
				uni.switchTab({
					url: '../index/index'
				})
			})
			setTimeout(()=>{
				if(getApp().globalData.isLogin){
					uni.switchTab({
						url: '../index/index'
					})
				}
			},1000)
		},
		methods:{
			login(){
				setTimeout(()=>{
					let that = this
					tt.login({
						success(res) {
							that.code = res.code
							that.$request(that.$api['account/getToken'], {
								code: res.code,
								vendor: 'FeiShu',
								grant_type: 'mini_app'
							}, data => {
								uni.hideLoading()
								uni.setStorageSync('token', data.token)
								that.$request(that.$api['user/getUsers'], {}, row => {
									getApp().globalData.account = row.account
									getApp().globalData.realName = row.realName
									getApp().globalData.organizationId = row.organizationId
									getApp().globalData.organizationName = row.organizationName
								})
								uni.$emit('login', data.account);
							}, err => {
								uni.hideLoading()
								uni.showToast({
									title: '登录出错'+JSON.stringify(err)
								})
							})
						},
						fail(res) {
							console.log(`login fail: ${JSON.stringify(res)}`);
						}
					});
					// uni.$emit('login',{msg:'登录成功'})
				},1000)
			},
			
		}
	}
</script>

<style lang="less" scoped>
	.main {
		width: 100%;
		height: 100vh;
	}
</style>
